package com.wangxinenpu.springbootdemo.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wangxinenpu.springbootdemo.dataobject.dto.user.UserListDto;
import com.wangxinenpu.springbootdemo.dataobject.model.Role;
import com.wangxinenpu.springbootdemo.dataobject.vo.user.UserVo;
import com.wangxinenpu.springbootdemo.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api ( value = "用户管理", tags = "用户管理" )
@AllArgsConstructor
public class UserController {

	private final UserService userService;

	@ApiOperation ( value = "获取用户列表", notes = "删除/批量删除" )
	@PostMapping ( "/pageList" )
	public R < Page < UserVo > > pageList( @RequestBody UserListDto dto ) {
		return userService.pageList( dto );
	}

	@PostMapping ( "/delete" )
	@ApiOperation ( value = "删除/批量删除", notes = "删除/批量删除" )
	public R < Boolean > delete( @RequestBody List < String > ids ) {
		return userService.delete( ids );
	}

	@GetMapping ( "/detail" )
	@ApiOperation ( value = "详情", notes = "详情" )
	public R < UserVo > detail( @RequestParam String id ) {
		return userService.detail( id );
	}

	@PostMapping ( "/savaOrUpdate" )
	@ApiOperation ( value = "新增/编辑", notes = "新增/编辑" )
	public R < Boolean > savaOrUpdate( @RequestBody @Validated UserVo dto ) {
		return userService.savaOrUpdate( dto );
	}

	@GetMapping ( "/getRoleList" )
	@ApiOperation ( value = "根据组织id获取角色", notes = "根据组织id获取角色" )
	public R < List < Role > > getRoleList( @RequestParam String orgId ) {
		return userService.getRoleList( orgId );
	}


}
